package com.etcn.common.utils;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

/**
 * 字符串工具类
 * @author guozc
 * @date 2016-08-10
 */
public class StringUtil extends org.apache.commons.lang3.StringUtils{

	/**
	 * 替换字符串中"${}"中制定的值
	 * @param str 原字符串
	 * @param replaces 替换的值
	 * @return
	 */
	public static String replaceFormal(String str,Map<String,String> replaces){
		String reg = "\\{([^}]+)\\}";
		Pattern p = Pattern.compile(reg);
		Matcher matcher = p.matcher(str);
		while(matcher.find()){
			String tempValue = matcher.group();
			tempValue = tempValue.substring(1 , tempValue.length()-1) ;
			String replace = replaces.get(tempValue);
			if(replace == null){
				replace = "";
			}
			str = str.replace("{"+tempValue+"}", replace);
		}
		return str;
	}
	
	/**
	 * 判断字符串是否不为空
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str){
		return StringUtils.isNotEmpty(str) && !"null".equals(str);
	}
	
}
